<?php
require './top/TopClient.php';
require './top/RequestCheckUtil.php';
require './top/Logger.php';
require './top/request/ItemGetRequest.php';
require './top/request/TaobaokeItemsConvertRequest.php';

class DouQinAction extends Action {
    var $PickRoot= "";
    var $TopClient =null;
    var $TaobaokeItemsConvertRequest=null;
    function __construct(){
    	load("@.dom");
        $this->PickRoot=PICK_DIR.MODULE_NAME.DIRECTORY_SEPARATOR;
        if(!is_dir($this->PickRoot)){
            mkdir($this->PickRoot);
        }
       
        $this->TopClient = new TopClient();
        $this->TopClient->appkey = "21087743";
        $this->TopClient->secretKey = "5f0cf1f8200d4854cb87410620878159";
        $this->TopClient->format="json";
        
        
        
        $this->TaobaokeItemsConvertRequest = new TaobaokeItemsConvertRequest();
        $this->TaobaokeItemsConvertRequest->setFields(
        		"click_url,num_iid,commission,commission_rate,commission_num,commission_volume");
        $this->TaobaokeItemsConvertRequest->setNick("douqin2010");
        $this->TaobaokeItemsConvertRequest->setPid(32295788);
        
    }
    
    function __destruct(){
      
    }
    
    public function index(){
    	  
    	$shopUrl = "http://shop36262227.taobao.com/";
    	$itme = file_get_html($shopUrl."search.htm?search=y&viewType=list&orderType=_hotsell&pageNum=1");
    	$Pages= substr($itme->find(".page-info",0)->innertext(), 2);
    	
    	for ($page = 1; $page <= $Pages; $page++) {
    		$itme = file_get_html($shopUrl."search.htm?search=y&viewType=list&orderType=_hotsell&pageNum=".$page);
    		foreach ($itme->find(".shop-hesper-bd .item ") as $k=>$it){
    			$url = parse_url($it->find("a",1)->href);
    			parse_str($url['query'], $urlout);
    			$CacheId =($urlout['id']);
    			$this->TaobaokeItemsConvertRequest->setNumIids($CacheId);
    			$TBCache = $this->TopClient->execute($this->TaobaokeItemsConvertRequest);
//                 $url ="http://local.douqin.com/sosopost/index.php?m=SoSoApi&a=goods&userid=10003&alid=154&tbid=".$CacheId;
//     			logCmd(file_get_contents($url));
    			sleep(1);
    			
    		}
    	}
    	
    	
      
    }
    
    public function goods(){
        
        $url ="http://local.douqin.com/sosopost/index.php?m=SoSoApi&a=picture";
        while (true){
            logCmd(file_get_contents($url));
//             sleep(1);
        }
    }
}